package com.ddn.util;



import java.util.concurrent.*;

/**
 * @author truman
 * @date 2022/9/2
 * @description 线程池工具类 单例模式
 */
public class ThreadPoolUtil {
    /**
     * 线程池对象
     */
    public ThreadPoolExecutor executor;
    /**
     * 私有化线程池工具类
     */
    private ThreadPoolUtil() {
        executor = new ThreadPoolExecutor(5,20,5, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
    }

    /**
     * 静态内部类,控制延迟加载，工具类
     */
    private static class ThreadPoolInner {
        private static final ThreadPoolUtil threadPoolUtil = new ThreadPoolUtil();
    }

    /**
     * 获取线程池工具类
     * @return
     */
    public static ThreadPoolUtil getInstence() {
        return ThreadPoolInner.threadPoolUtil;
    }
}
